This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#define IMW __IMW_keyword__ // image width (px) | |
#define IMH __IMH_keyword__ // image height (px) | |
#define BX __BX_keyword__ // block index x | |
#define BY __BY_keyword__ // block index y | |
#define nTPB (BX*BY) // threads per block | |
#define IMN 21 // buffer length |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Check if PyCuda is installed | |
package_name = 'pycuda' | |
use_cuda = importlib.util.find_spec(package_name) is not None | |
if use_cuda: | |
import pycuda.driver as cuda | |
import pycuda.autoinit | |
from pycuda.compiler import SourceModule |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# run multiply function on GPU | |
multiply_func( | |
result_gpu, a_gpu, b_gpu, | |
block=(100, 1, 1), | |
grid=(1, 1, 1) | |
) | |
# Get data back from GPU | |
cuda.memcpy_dtoh(result, result_gpu) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# create Python variables | |
a = np.random.randn(100).astype(np.float32) | |
b = np.random.randn(100).astype(np.float32) | |
result = np.random.randn(100).astype(np.float32) | |
# allocate memory on GPU | |
a_gpu = cuda.mem_alloc(a.nbytes) | |
b_gpu = cuda.mem_alloc(b.nbytes) | |
result_gpu = cuda.mem_alloc(b.nbytes) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
import pycuda.driver as cuda | |
import pycuda.autoinit | |
from pycuda.compiler import SourceModule | |
# Define our function using CUDA code | |
cuda_func_def = """ | |
__global__ void multiply(float *result, float *a, float *b) | |
{ | |
const int i = threadIdx.x; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from fastapi import APIRouter | |
from service.core.models.output import MessageOutput | |
from service.core.models.input import MessageInput | |
from service.core.logic.business_logic import run_prime_factor_calculation | |
router = APIRouter() | |
@router.post("/hello", response_model=MessageOutput, tags=["hello post"]) | |
def hello_endpoint(inputs: MessageInput): | |
# Respond to requests on the hello endpoint |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from pydantic import BaseModel, Field | |
class MessageOutput(BaseModel): | |
message1: str = Field(..., title="Greeting") | |
message2: str = Field(..., title="Calculation result") | |
n: int = Field(..., title="n: a large integer") | |
largest_prime_factor: int = Field(..., title="Largest prime factor of n") | |
elapsed_time: float = Field(..., title="Calculation time (seconds)") |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import datetime | |
from hypothesis.strategies import dates | |
from hypothesis import given | |
from truth.truth import AssertThat | |
# Module under test | |
from app.core.worker import Worker | |
# Generate dates within the four digit year range |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Show some generated text examples | |
from hypothesis.strategies import text | |
for _ in range(10): | |
text().example() | |
# '' | |
# '\x17\x14' | |
# '\x1d\x08' | |
# '(\U000adacd\x0e\x02\x1e' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from sklearn.feature_extraction.text import TfidfVectorizer | |
from sklearn.metrics.pairwise import linear_kernel | |
from nltk import word_tokenize | |
from nltk.stem import WordNetLemmatizer | |
import nltk | |
from nltk.corpus import stopwords | |
# Download stopwords list | |
nltk.download('punkt') | |
stop_words = set(stopwords.words('english')) |
NewerOlder